package com.monlyu.util.convertor;

import java.util.Map;

import org.apache.struts2.util.StrutsTypeConverter;

/**
 * @since Fan Houjun 2008-12-9
 */
public class BooleanConverter extends StrutsTypeConverter {

	/**
	 * @see org.apache.struts2.util.StrutsTypeConverter#convertFromString(java.util.Map,
	 *      java.lang.String[], java.lang.Class)
	 */
	public Object convertFromString(Map context, String[] values, Class toClass) {
		if (values != null && values.length > 0 && values[0] != null && values[0].length() > 0) {
			return Boolean.valueOf("1".equals(values[0]) || "true".equals(values[0]));
		}
		return null;
	}

	/**
	 * @see org.apache.struts2.util.StrutsTypeConverter#convertToString(java.util.Map,
	 *      java.lang.Object)
	 */
	public String convertToString(Map context, Object obj) {
		// 未做任何处理
		return obj.toString();
	}
}
